<?php

namespace app\admin\model;

use think\Db;
use think\Model;


class Vehicle extends Model
{

    

    

    // 表名
    protected $name = 'vehicle';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;
    protected $resultSetType = 'collection';


    // 追加属性
    protected $append = [
        'create_time_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    



    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function getHierarchy()
    {
        return ['1' => '厂牌', '2' => '车型', '3' => '排量', '4' => '年份', 5 => '款型'];
    }

    public function getHot()
    {
        return ['hot' => '热门', 'nohot' => '默认'];
    }
    

    public function vehidelete($id,$array = [])
    {

        $dataList = Db::name('vehicle')->where('pid',$id)->where('del',0)->select();

            foreach($dataList as $key => $val)
            {
                $array[] = $val['id'];
                $array = $this->vehidelete($val['id'],$array);
//                $array = array_merge($array,$this->cycledel($item,$val['id']));
            }
            return $array;
    }


}
